Add FrameworkReference to Microsoft.Aspnetcore.App for non-SharedFx projects with SharedFx-only references#65478
Merged
Add FrameworkReference to Microsoft.Aspnetcore.App for non-SharedFx projects with SharedFx-only references#65478
Conversation
bbcecb9 to
d4b02b5
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adjusts the repo’s MSBuild reference-resolution/pack behavior so that non-SharedFx, packable projects that reference SharedFx-only assemblies can surface a Microsoft.AspNetCore.App framework dependency via restore assets (so packing can pick it up).
Changes:
- Capture the
Microsoft.AspNetCore.AppKnownFrameworkReferencebefore it’s removed globally, so it can be reintroduced conditionally. - Conditionally add a
FrameworkReferencetoMicrosoft.AspNetCore.Appfor packable, non-SharedFx projects with SharedFx-only project references, and add a target to remove the framework reference beforeResolveFrameworkReferences.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| eng/targets/ResolveReferences.targets | Adds conditional Microsoft.AspNetCore.App framework reference (and re-adds the known framework reference) plus a target that removes the framework reference before ResolveFrameworkReferences. |
| Directory.Build.targets | Captures the KnownFrameworkReference for Microsoft.AspNetCore.App into an internal item before it gets removed. |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
ericstj
reviewed
Feb 24, 2026
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <_RemovedAspNetKnownFrameworkReference Include="@(KnownFrameworkReference->WithMetadataValue('Identity', 'Microsoft.AspNetCore.App'))" /> |
Member
There was a problem hiding this comment.
Rather than removing this and adding it back did you consolidating the logic?
Member
Author
|
/backport to release/11.0-preview2 |
Contributor
|
Started backporting to |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #65410
Projects that are are not in the shared framework, ship as packages, and have references to libraries that only ship in the shared framework, should wind up with a FrameworkReference to Microsoft.AspNetCore.App in their .nuspec. We used to have a custom post-build task that injected that FrameworkReference, but that went away in #64863.
This is a bit of a hack - we add a FrameworkReference to the affected projects, so that Restore can put that FrameworkRef into the generated assets file. Then we remove that FrameworkReference prior to
ResolveFrameworkReferencesso that the ProjectReferences get used instead. We also have to add aIsTransitiveFrameworkReference=truemetadata to the FrameworkReference so that pruning warnings don't kick in: https://github.com/dotnet/sdk/blob/e90c4413024970eca97d05122243737aa207af11/src/Tasks/Microsoft.NET.Build.Tasks/GetPackagesToPrune.cs#L103-L104. It would be great if there was metadata we could set on the FrameworkReference (something like "NuspecOnly"), so that none of the references from the FrameworkReference would actually be raised, and pruning warnings wouldn't fire, but the FrameworkRef would still wind up in project.assets.json & the .nuspec.